<template>
	<view class="advanced">
		<block v-if="seniorInfo">
			<view class="advanced-banner">
				<image :src="seniorInfo.image" mode="widthFix"></image>
			</view>
			<view class="advanced-brand">
				<view class="advanced-brand-tit">
					<text class="span">品牌推荐</text>
					<text class="em">/Brand recommendation</text>
				</view>
				<view class="advanced-brand-list">
					<u-sticky bgColor="transparent" h5-nav-height="0" @fixed="stickyFixed" @unfixed="stickyUnfixed">
						<view class="tabs" :class="{isFixed}">
							<scroll-view :scroll-x="isShowAll?false:true" class="brand-list">
								<view class="tit" v-if="isShowAll">全部</view>
								<view class="brand-items" :class="{isShowAll}">
									<view class="brand-item" v-for="(data,index) in seniorInfo.brand_list" :key="index" @click="switchBrandInfo(index)" :class="{active: brandIndex==index}">
										{{data.factory_name}}
									</view>
								</view>
							</scroll-view>
							<view class="arrow" @click="showAll">
								<u-icon :name="isShowAll?'arrow-up-fill':'arrow-down-fill'" size="24"></u-icon>
							</view>
						</view>
					</u-sticky>
					<view class="advanced-brand-info" v-if="brandInfo">
						<view class="dl">
							<view class="dt">
								<image :src="brandInfo.cover_img" mode="widthFix"></image>
							</view>
							<view class="dd">
								<view class="h1">{{brandInfo.factory_name}}</view>
								<view class="span"></view>
								<view class="p">{{brandInfo.brief}}</view>
								<view class="more" @click="checkMore(brandInfo.factory_id)">查看更多</view>
							</view>
						</view>
						<image class="bg" src="https://jiajudashi.oss-cn-shenzhen.aliyuncs.com/static/images/other/2022-09-16/20220916/8b6fc475796780dd7536a1e161138c68.png"></image>
					</view>
				</view>
				<view class="advanced-goods">
					<view class="advanced-goods-tit">
						<view class="span">产品推荐</view>
						<view class="p">New series</view>
					</view>
					<view class="goods-items">
						<view class="goods-item" v-for="(data,index) in goodsList" :key="index" @click="goGoodsInfo(data)">
							<image mode="aspectFill" :src="data.image" style="width: 204rpx; height: 178rpx; border-radius: 16rpx"></image>
							<view class="dl">
								<view class="dd">
									<view class="h1">{{data.goods_name}}</view>
									<view class="p">零售价:￥<text>{{data.retail_price}}</text></view>
								</view>
							</view>
						</view>
					</view>
					<view class="more" @click="checkMore(brandInfo.factory_id)">查看更多<text></text></view>
				</view>
				<view class="advanced-imgs">
					<image :src="data.wx_image" mode="widthFix" v-for="(data,index) in seniorInfo.image_list" :key="index" @click="checkMore(data.factory_id)"></image>
				</view>
			</view>
		</block>
		<pt-loading></pt-loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				seniorInfo: '',
				brandIndex: 0,
				goodsList: [],
				isFixed: false,
				isShowAll: false
			}
		},
		computed: {
			brandInfo(){
				if(this.seniorInfo.brand_list && this.seniorInfo.brand_list.length){
					return this.seniorInfo.brand_list[this.brandIndex]
				}
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			async init(){
				const { datas } = await this.$u.api.SeniorList({senior_id: 1})
				this.seniorInfo = datas
				this.getGoods()
			},
			async getGoods(){
				const { datas } = await this.$u.api.SeniorFactoryGoodsList({senior_factory_id: this.brandInfo.id, limit: 8})
				this.goodsList = datas.data
			},
			switchBrandInfo(index){
				this.brandIndex = index
				this.getGoods()
			},
			goGoodsInfo(data){
				uni.navigateTo({
					animationDuration: 500,
					url: `/pages/product-info/product-info?goods_id=${data.goods_id}`
				})
			},
			checkMore(factory_id){
				uni.navigateTo({
					animationDuration: 500,
					url: `/brand-list/brand-info/brand-info?type=1&factory_id=${factory_id}`
				})
			},
			stickyFixed(){
				this.isFixed = true
			},
			stickyUnfixed(){
				this.isFixed = false
			},
			showAll(){
				this.isShowAll = !this.isShowAll
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #EAEAEA;
	}
	.advanced{
		padding: 24rpx;
		.tabs{
			position: relative;
			height: 100%;
			transition: all .5s;
			display: flex;
			align-items: flex-start;
			&.isFixed{
				background-color: #FFF;
				padding: 0 30rpx;
			}
			.brand-list{
				flex: 1;
				min-width: 0;
			}
			.arrow{
				padding: 30rpx 20rpx;
			}
		}
		.advanced-banner{
			image{
				width: 100%;
			}
		}
		.advanced-brand{
			padding-top: 40rpx;
			.advanced-brand-tit{
				border-bottom: solid 1px #CACACA;
				padding-bottom: 20rpx;
				position: relative;
				&::after{
					content: '';
					position: absolute;
					width: 24rpx;
					height: 4rpx;
					border-radius: 8rpx;
					background-color: #D35345;
					left: 0;
					bottom: 14rpx;
				}
				.span{
					font-weight: bold;
					font-size: 32rpx;
				}
				.em{
					margin-left: 10rpx;
					font-size: 22rpx;
					color: #B2AEAE;
				}
			}
			.advanced-brand-list{
				.brand-list{
					padding: 30rpx 0;
					.tit{
						line-height: 40rpx;
						font-size: 32rpx;
						font-weight: bold;
					}
					.brand-items{
						white-space: nowrap;
						&.isShowAll{
							white-space: normal;
							.brand-item{
								margin-top: 20rpx;
								width: 31.3%;
								white-space: nowrap;
								margin-right: 3%;
								overflow: hidden;
								text-overflow: ellipsis;
								&:nth-child(3n){
									margin-right: 0;
								}
							}
						}
						.brand-item{
							display: inline-block;
							vertical-align: top;
							line-height: 40rpx;
							border: solid 1rpx #CACACA;
							border-radius: 40rpx;
							min-width: 160rpx;
							text-align: center;
							padding: 0 20rpx;
							// transition: all .5s;
							margin-right: 30rpx;
							font-size: 22rpx;
							&.active{
								background-color: #000;
								border-color: #000;
								color: #FFF;
							}
						}
					}
				}
			}
			.advanced-brand-info{
				position: relative;
				.dl{
					position: relative;
					z-index: 1;
					.dt{
						image{
							width: 100%;
							border: solid 4rpx #FFF;
						}
					}
					.dd{
						flex: 1;
						min-width: 0;
						margin-top: 30rpx;
						.h1{
							font-size: 28rpx;
							font-weight: bold;
						}
						.span{
							display: inline-block;
							vertical-align: top;
							width: 14px;
							height: 3px;
							background-color: #000;
							margin: 10rpx 0 20rpx;
						}
						.p{
							font-size: 20rpx;
							color: #4D4D4D;
							line-height: 40rpx;
						}
						.more{
							margin-top: 20rpx;
							background-color: #D35345;
							color: #FFF;
							line-height: 40rpx;
							width: 130rpx;
							text-align: center;
							border-radius: 40rpx;
							display: inline-block;
							vertical-align: top;
							font-size: 22rpx;
						}
					}
				}
				.bg{
					position: absolute;
					width: 640rpx;
					height: 210rpx;
					right: 0;
					top: 50%;
					transform: translateY(-50%);
				}
			}
		}
		.advanced-goods{
			border: solid 1px #BABABA;
			border-radius: 50rpx;
			padding: 30rpx;
			margin-top: 70rpx;
			.advanced-goods-tit{
				margin-top: -55rpx;
				.span{
					font-weight: bold;
					font-size: 32rpx;
					background-color: #EAEAEA;
					display: inline-block;
					vertical-align: top;
					padding: 0 20rpx;
					color: #3B3A38;
				}
				.p{
					padding: 10rpx 20rpx 0;
					font-size: 20rpx;
					color: #666;
				}
			}
			.goods-items{
				display: flex;
				flex-wrap: wrap;
				.goods-item{
					width: 204rpx;
					margin-top: 20rpx;
					margin-right: 12rpx;
					background: linear-gradient(to bottom, #FCF7F3, #F9EDD7);
					border-radius: 16rpx;
					&:nth-child(3n){
						margin-right: 0;
					}
					.dl{
						display: flex;
						align-items: center;
						padding: 20rpx 10rpx;
						.dd{
							flex: 1;
							min-width: 0;
							margin-right: 10px;
							.h1{
								font-size: 22rpx;
								font-weight: bold;
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
							}
							.p{
								font-size: 20rpx;
								margin-top: 10rpx;
								display: flex;
								white-space: nowrap;
								text{
									font-weight: bold;
									font-size: 24rpx;
									color: #C66143;
									font-family: 'din';
								}
							}
						}
					}
				}
			}
			.more{
				display: flex;
				margin: 30rpx auto 0;
				align-items: center;
				justify-content: center;
				background-color: #D35345;
				color: #FFF;
				width: 200rpx;
				height: 50rpx;
				border-radius: 50rpx;
				font-size: 24rpx;
				text{
					width: 24rpx;
					height: 24rpx;
					border-radius: 50%;
					display: flex;
					align-items: center;
					justify-content: center;
					background-color: #FFF;
					margin-left: 10rpx;
					&::after{
						content: '';
						width: 5rpx;
						height: 5rpx;
						border-top: 2rpx solid #D35345;
						border-right: 2rpx solid #D35345;
						transform: rotate(45deg);
					}
				}
			}
		}
		.advanced-imgs{
			margin: 30rpx -24rpx 0;
			image{
				display: block;
				width: 100%;
				vertical-align: top;
				cursor: pointer;
			}
		}
	}
</style>
